//
//  UIImage+ZZUtil.h
//  OCFrame
//
//  Created by hfzhangzhang on 2016/12/19.
//  Copyright © 2016年 hfzhangzhang. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIImage (ZZUtil)

/**
 *  生成纯色UIImage
 *
 *  @param   color  颜色
 *  @param   size   image尺寸
 *  @return  纯色UIImage
 */
+ (UIImage *)zz_imageWithColor:(UIColor *)color size:(CGSize)size;
+ (UIImage *)zz_imageWithColor:(UIColor *)color;

/**
 *  生成渐变色UIImage
 *
 *  @param size             尺寸
 *  @param direction        渐变方向(默认{0,1}, 垂直向下)
 *  @param colors           颜色数组(UIColor 或 CGColorRef)
 *  @return                 渐变色UIImage
 */
+ (UIImage *)zz_imageWithColors:(NSArray *)colors size:(CGSize)size direction:(CGPoint)direction;
+ (UIImage *)zz_imageWithColors:(NSArray *)colors size:(CGSize)size;

/**
 *  取图片某一像素的颜色
 *
 *  @param point    图片上的点
 *  @return         该点像素的颜色
 */
- (UIColor *)zz_colorAtPixel:(CGPoint)point;



@end


@interface UIImage (transform)

/**
 *  压缩图片至 size(单位KB) 以下大小, 如无法压至该尺寸以下, 则取最大压缩尺寸
 *
 *  @param size    要求大小上限, 单位KB
 *  @return        压缩后的NSData
 */
- (NSData *)zz_transformToDataBelowSize:(CGFloat)size;

/** 截取当前image对象rect区域内的图像 */
- (UIImage *)zz_subImageWithRect:(CGRect)rect;

/** 压缩图片至指定尺寸 */
- (UIImage *)zz_rescaleImageToSize:(CGSize)size;

/** 压缩图片至指定像素 */
- (UIImage *)zz_rescaleImageToPX:(CGFloat )toPX;

/** 在指定的size里面生成一个平铺的图片 */
- (UIImage *)zz_getTiledImageWithSize:(CGSize)size;

/** 渲染图片颜色为 color */
- (UIImage *)zz_renderedImageWithColor:(UIColor *)color;

/** 获得灰度图 */
- (UIImage *)zz_grayImage;

/** UIView转化为UIImage */
+ (UIImage *)zz_imageFromView:(UIView *)view;

/** 将两个图片生成一张图片 */
+ (UIImage *)zz_mergeImage:(UIImage *)firstImage withImage:(UIImage *)secondImage;
- (UIImage *)zz_mergedImageWithImage:(UIImage *)image;


/**
 *  纠正图片的方向
 *
 *  @return UIImage
 */
- (UIImage *)zz_fixOrientation;

/**
 *  按给定的方向旋转图片
 *
 *  @param orient   UIImageOrientation枚举类
 *  @return         UIImage
 */
- (UIImage*)zz_rotate:(UIImageOrientation)orient;

/**
 *  垂直翻转
 *
 *  @return UIImage
 */
- (UIImage *)zz_flipVertical;

/**
 *  水平翻转
 *
 *  @return UIImage
 */
- (UIImage *)zz_flipHorizontal;

/**
 *  将图片旋转degrees角度
 *
 *  @param degrees   角度
 *  @return          UIImage
 */
- (UIImage *)zz_imageRotatedByDegrees:(CGFloat)degrees;

/**
 *  将图片旋转radians弧度
 *
 *  @param radians   弧度
 *  @return          UIImage
 */
- (UIImage *)zz_imageRotatedByRadians:(CGFloat)radians;


@end


@interface UIImage (Gif)

/**
 *  通过gif生成UIImage
 *
 *  @param gifData   GIFData
 *  @return          UIImage
 */
+ (UIImage *)zz_animatedImageWithGIFData:(NSData *)gifData;

/**
 *  通过gif生成UIImage
 *
 *  @param gifURL   GIF路径
 *  @return         UIImage
 */
+ (UIImage *)zz_animatedImageWithGIFURL:(NSURL *)gifURL;

@end

@interface UIImage (Filter)

- (void)zz_imageWithFilterName:(NSString *)filterName completion:(void(^)(UIImage *image))completion;
- (void)zz_imageWithFilterName:(NSString *)filterName options:(NSDictionary *)options completion:(void(^)(UIImage *image))completion;
- (UIImage *)zz_invertImage;
- (UIImage *)zz_blurredImage;
- (UIImage *)zz_blurredImageWithRadius:(CGFloat)radius;

@end


